﻿using System;
using System.Collections.Generic;
using Common;
using ImageProcessing.Common;
using ImageProcessing.Detectors;
using ImageProcessing.Storage;

namespace ImageProcessing.Engine
{
    public abstract class BaseImageProcessingEngine : IDisposable
    {
        public int MinFoundPoints { get; set; }
        public IPersistanceDB DBConnection { get; set; }

        protected readonly DetectorType _detectType = DetectorType.FastHessian;


        protected BaseImageProcessingEngine(DetectorType detectorType)
        {
            MinFoundPoints = 5;
            _detectType = detectorType;
        }

        protected static IInterestPointDetector BuildDetector(DetectorType detectorType, int width, int height)
        {
            IInterestPointDetector ipd;
            switch (detectorType)
            {
                case DetectorType.FastHessian:
                    ipd = new FastHessian(0.0001f, 5, 2, width, height, new IntegralImage(width, height));
                    break;
                case DetectorType.FastCorner:
                    ipd = new FastDetector(width, height);
                    break;
                default:
                    throw new NotImplementedException();
            }
            return ipd;
        }

        protected void AddNameToPoints(TagInfo tagInfo, List<InterestPoint> points)
        {
            int length = points.Count;
            for (int index = 0; index < length; index++)
            {
                points[index].SetTagInfo(tagInfo);
            }
        }


        public abstract void Dispose();
    }
}
